//引入模块
const fs = require('fs')
const path = require('path')
let data = fs.readFileSync(path.join(__dirname, './infor.json'), 'utf-8')
    // let data = fs.readFileSync(path.join(__dirname, './a.txt'), { encoding: 'utf-8' })
    // let data = fs.readFileSync(path.join(__dirname, './a.txt'), 'utf-8')
console.log(path.join(__dirname, './infor.json'))
    // console.log(data);
    //转换为对象
const a = JSON.parse(data) //将字符串转换为对象
console.log(a);
//解构
// const { id, name, count } = a
// const data2 = a.map((el, i) => {
//     return [el.id, el.name, el.count]

// })
// console.log(data2);
let num = Math.floor(Math.random() * a.length)
console.log(num);
console.log(a[num]);
const add = function() {
    a[num].count++

}()

console.log(a[num]);
fs.writeFileSync(path.join(__dirname, './infor.json'), JSON.stringify(a))